<%@page import="java.util.ArrayList"%>
<%@page import="statics.SoptVars"%>
<%@page import="comm.util.RequestManager"%>
<%@page import="comm.util.SoptHashMap"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.ParseException"%>
<%@page import="sopt.engSearch.DaumSearchProc"%>
<%@page import="sopt.engSearch.NaverSearchProc"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	SoptHashMap hm = RequestManager.getRequest(request);
	
	ArrayList blogSearch = new ArrayList();
	ArrayList imgSearch = new ArrayList();
	ArrayList vidSearch = new ArrayList();
	ArrayList newsSearch = new ArrayList();
	int curPage = 1;
	if(hm!=null){
		if(hm.get("PAGE")!=null)
			curPage=Integer.parseInt(hm.get("PAGE").toString());
		if(hm.get("Q")!=null){
			newsSearch = NaverSearchProc.getNewsResult(hm.get("Q").toString(),curPage,8);
			blogSearch = NaverSearchProc.getBlogResult(hm.get("Q").toString(),curPage,8);
			imgSearch = NaverSearchProc.getImageResult(hm.get("Q").toString(),curPage,8);
			vidSearch = NaverSearchProc.getVidResult(hm.get("Q").toString(),curPage,8);
		}
	}
%>



<div id="newsSearch" class="newsSearch">
	<div>powered by Naver</div>
	<div class="resultHeaders">
		<span style="float:right;">뉴스 검색 결과 (<%=newsSearch.size() %>) <a href="javascript:hideResult('newsSearch');">hide</a> <a href="javascript:showResult('newsSearch');">show</a></span>
	</div>
	<div id="newsSearchContent">
	<%for(int i=0;i<newsSearch.size();i++){
		
		SoptHashMap tempHm = (SoptHashMap)newsSearch.get(i);
		String pubdate = tempHm.get("PUBDATE").toString();
		
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
   		Date date = new Date();
			try {
				date = format.parse(pubdate);
				format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				
				pubdate = format.format(date);
			} catch (ParseException e1) {
				//
			}
		%>
	<div class="g">
		<p class="title"><a href='<%=tempHm.get("LINK")%>' target="_blank"><%=tempHm.get("TITLE")%></a></p>
		<p class="authorPubdate"><%=pubdate%></p>
		<p class="desc"><%=tempHm.get("DESCRIPTION")%></p>
		<p class="link"><a href='<%=tempHm.get("ORIGINALLINK")%>' target="_blank">원문보기</a></p>
		
	</div>
	<%} %>
	</div>
</div>
<div id="blogSearch" class="blogSearch">
	<div class="resultHeaders">
		<span style="float:right;">블로그 검색 결과 (<%=blogSearch.size() %>) <a href="javascript:hideResult('nblogSearch');">hide</a> <a href="javascript:showResult('nblogSearch');">show</a></span>
	</div>
	<div id="nblogSearchContent">
	<%for(int i=0;i<blogSearch.size();i++){
		SoptHashMap tempHm = (SoptHashMap)blogSearch.get(i);		
		%>
	<div class="g">
		<p class="title"><a href='<%=tempHm.get("LINK")%>' target="_blank"><%=tempHm.get("TITLE")%></a></p>
		<p class="authorPubdate"><%=tempHm.get("BLOGGERNAME")%></p>
		<p class="desc"><%=tempHm.get("DESCRIPTION")%></p>
		<p class="link"><a href='<%=tempHm.get("LINK")%>' target="_blank">원문보기</a></p>
		
	</div>
	<%} %>
	</div>
</div>
<div class="imgSearch">
	<div class="resultHeaders">
		<span style="float:right;">이미지 검색 결과 (<%=imgSearch.size() %>) <a href="javascript:hideResult('nimgSearch');">hide</a> <a href="javascript:showResult('nimgSearch');">show</a></span>
	</div>
	<div id="nimgSearchContent">
	<%
	String result = "";
	for(int i=0;i<imgSearch.size();i++){
		SoptHashMap tempHm = (SoptHashMap)imgSearch.get(i);
		String title = tempHm.get("TITLE").toString();
		String link = tempHm.get("LINK").toString();
		String thumbnail = tempHm.get("THUMBNAIL").toString();
		String width = tempHm.get("WIDTH").toString();
		String height = tempHm.get("HEIGHT").toString();

   		result +=
   			"<div class='gImg'>" +
				"<p><a href='"+link+"' target='_blank'>" +
						"<img class='gImgThumb' src='"+ thumbnail+ "' width='150' />"+
   			"</a></p>";
   		
   		result +=
   			"<p><a href='"+link+"' target='_blank' class='linkGreen'>크게보기</a></p>"+
				"</div>";
	}
	%>
	<%=result %>
	<div class="clear"></div>
	</div>
</div>
<div class="vidSearch">
	<div class="resultHeaders">
		<span style="float:right;">동영상 검색 결과 (<%=vidSearch.size()%>) <a href="javascript:hideResult('nvidSearch');">hide</a> <a href="javascript:showResult('nvidSearch');">show</a></span>
	</div>
	<div id="nvidSearchContent">
	<%
	result = "";
	for(int i=0;i<vidSearch.size();i++){
		SoptHashMap tempHm = new SoptHashMap();
		tempHm = (SoptHashMap)vidSearch.get(i);
		
		String title = tempHm.get("TITLE").toString();
	
		String link = tempHm.get("LINK").toString();
		
		String thumbnail = tempHm.get("THUMBNAIL").toString();
		
			result +=
				"<div class='gVid'>" +
				"<div class='gVidThumbBg'><a href='"+link+"' target='_blank'>" +
						"<img class='gVidThumb' src='"+ thumbnail+ "' width='175' />"+
				"</a></div>" +
				"<div class='gVidDesc'><p><a href='"+link+"' target='_blank'>" +
				title +
				"</a>" +
				"</p>" +
				"<div class='resultknowAuthor'>" +
				"</div>";
			
			result+="</div></div>";
		}
	
	result+="</div>";
	%>
	<%=result %>
	</div>
</div>
